`include "chunjun_define.sv" 
`include "chunjun_lib_define.sv" 

//================================================================================================
// File Name   : wing_cbb_aomux_idx.sv
// Create Time : Wed Nov 20 10:39:18 2024
// Description :
// 
//================================================================================================

module wing_cbb_aomux_idx #(
    parameter   NUM    = 16,
    // Declare either WIDTH or T.
    parameter   WIDTH  = 16,
    parameter   type T = logic [WIDTH-1:0],
    // Don't change following parameter.
    parameter   IDX_W  = $clog2(NUM)
) (
    input   T     [NUM-1:0]   data_arr,
    input   logic [IDX_W-1:0] sel_idx,
    output  T                 data_sel
);
 
if (NUM == 1) begin : G_NUM1

assign data_sel = data_arr;
 
end else begin : G_NUM
 
localparam T_W = $bits(T);
 
logic [T_W-1:0] data_sel_pre;

always_comb begin : G_DATA_SEL
  data_sel_pre     = {T_W{1'b0}};
  for (int i=0; i<NUM; i++) begin : G_ITER
    data_sel_pre   = data_sel_pre | ( {T_W{sel_idx == i}} & data_arr[i]);
  end
end

assign data_sel = T'(data_sel_pre);
 
end // G_NUM
 
endmodule

`include "chunjun_undefine.sv" 
